package cn.haoma.base.geo.app;

import java.util.HashSet;

public class GeoTreeSet {
    public GeoTree root = new GeoTree();

    public HashSet getEndSet(int... indexPath) {
        GeoTree geoTree = root;
        for (int i = 0; i < GeoConfig.LEVEL; i++) {
            GeoTree leaf = (GeoTree) geoTree.getLeaf(indexPath[i]);
            if (null == leaf) {
                synchronized (geoTree) {
                    if (null == geoTree.getLeaf(indexPath[i])) {
                        leaf = new GeoTree();
                        geoTree.setLeaf(leaf, indexPath[i]);
                    } else {
                        leaf = (GeoTree) geoTree.getLeaf(indexPath[i]);
                    }
                }
            }
            geoTree = leaf;
        }

        HashSet endSet = (HashSet) geoTree.getLeaf(indexPath[GeoConfig.LEVEL]);
        if (endSet == null) {
            endSet = new HashSet();
        }

        return endSet;
    }


}
